/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aal.model;

import com.aal.business.OrderManagementLocal;
import com.aal.entity.OrderProduct;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author quy
 */
public class OrderManagement {
    OrderManagementLocal orderManagement = lookupOrderManagementLocal();
   private long OrderID;
   private String username;
   private Date orderdate;
   private double totalnetprice;
   private double discountvalue;
   private double shippingcost;
   private double taxcost;
   private double totalprice;
   private int status;
   private String shippingaddress;
   private String receivername;
   private String receiverphone;
   private String customername;
   private String billingaddress;

    public String getBillingaddress() {
        return billingaddress;
    }

    public void setBillingaddress(String billingaddress) {
        this.billingaddress = billingaddress;
    }

    public String getCustomername() {
        return customername;
    }

    public void setCustomername(String customername) {
        this.customername = customername;
    }
   
    public long getOrderID() {
        return OrderID;
    }

    public void setOrderID(long OrderID) {
        this.OrderID = OrderID;
    }

    public double getDiscountvalue() {
        return discountvalue;
    }

    public void setDiscountvalue(double discountvalue) {
        this.discountvalue = discountvalue;
    }

    public Date getOrderdate() {
        return orderdate;
    }

    public void setOrderdate(Date orderdate) {
        this.orderdate = orderdate;
    }

    public String getReceivername() {
        return receivername;
    }

    public void setReceivername(String receivername) {
        this.receivername = receivername;
    }

    public String getReceiverphone() {
        return receiverphone;
    }

    public void setReceiverphone(String receiverphone) {
        this.receiverphone = receiverphone;
    }

    public String getShippingaddress() {
        return shippingaddress;
    }

    public void setShippingaddress(String shippingaddress) {
        this.shippingaddress = shippingaddress;
    }

    public double getShippingcost() {
        return shippingcost;
    }

    public void setShippingcost(double shippingcost) {
        this.shippingcost = shippingcost;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public double getTaxcost() {
        return taxcost;
    }

    public void setTaxcost(double taxcost) {
        this.taxcost = taxcost;
    }

    public double getTotalnetprice() {
        return totalnetprice;
    }

    public void setTotalnetprice(double totalnetprice) {
        this.totalnetprice = totalnetprice;
    }

    public double getTotalprice() {
        return totalprice;
    }

    public void setTotalprice(double totalprice) {
        this.totalprice = totalprice;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    public boolean getCreateOrderDetail(){
        return false;
    }
    public Long getPlaceOrder(){
        boolean ok = orderManagement.placeOrder(username, orderdate, totalnetprice, discountvalue, shippingcost, taxcost, totalprice, status, shippingaddress, receivername, receiverphone,customername,billingaddress);
        return ok ? orderManagement.maxOrderId() : -1;
    }
    public boolean getEditOrderStatus(){
        return orderManagement.editOrderStatus(OrderID, status);
    }
    public OrderProduct getOrderProduct(){
        return orderManagement.getOrderProduct(OrderID);
    }
    public List<OrderProduct> getViewAll(){
        return orderManagement.viewAll();
    }
    public boolean createOrderDetail(long orderId,int productId,int quantity,double totalNetPrice,double shippingCost,double taxCost){
        return orderManagement.createOrderDetail(orderId, productId, quantity, totalNetPrice, shippingCost, taxCost);
    }
    private OrderManagementLocal lookupOrderManagementLocal() {
        try {
            Context c = new InitialContext();
            return (OrderManagementLocal) c.lookup("java:global/AAL/AAL-ejb/OrderManagement!com.aal.business.OrderManagementLocal");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
